//===================================
//File: SpecSpecImage.cpp
//SpecSpecImage functions
//Name: Smirnova O.P.
//Date: 28.06.12, v.1.0
//===================================

#include "Specimage.h"

using namespace std;

unsigned int SpecImage::count=0;
unsigned int SpecImage::count_all=0;

SpecImage::SpecImage(Tube tube, Body body, Throat throat)
	:Image(body, throat)
{
	count_all++;
    id=count_all;
	count++;
   // cout <<endl
//	<<"\nSpecImage() ";
 //   cout <<" id=" <<id<<":\n";
    this->tube = tube;
    this->points->addElemToEnd(this->tube.getPoint());
//	cout <<" id=" <<id<<endl
 //   <<" SpecImage."<<endl;
};

SpecImage::~SpecImage()
{
	//cout << "\n~SpecImage:\n";
	//points->deleteList();
//	cout << "~SpecImage\n";
	
};


void SpecImage::moveTo(const Point p)
{
    Point el = body.getTrapeze().getPointC();
	Point pt = p;
	float dx = pt.getX()-el.getX();
	float dy = pt.getY()-el.getY();
	Elem<Point> *temp = points->getHead();
	Elem<Point> *head = points->getHead();
	do
	  {
		el = temp->getValue();
		el.moveTodXdY(dx,dy);
		temp->setValue(el);
		temp = temp->getNext();
	  }while(head!=temp);
   body.moveTo(p);
   throat.moveTo(p);
   tube.moveTo(p);
};


void SpecImage::moveTodXdY(const double x, const double y)
{
	Point el;
	body.moveTodXdY(x,y);
	throat.moveTodXdY(x,y);
	tube.moveTodXdY(x, y);
    Elem<Point>* temp = points->getHead();
	
	Elem<Point> *head = points->getHead();
	do
	  {
		el = temp->getValue();
		el.moveTodXdY(x,y);
		temp->setValue(el);
		temp = temp->getNext();
	  }while(head!=temp);

};

void SpecImage::consSF (const Point p)
{
	Point el;
	body.consSF(p);
	throat.consSF(p);
	tube.consST(p);
    Elem<Point>* temp = points->getHead();
	
	Elem<Point> *head = points->getHead();
	do
	  {
		el = temp->getValue();
		Point pt = p;
		el.consSP(pt);
		temp->setValue(pt);
		temp = temp->getNext();
	  }while(head!=temp);
};




const unsigned int SpecImage::getID()
{
  return id;
};

unsigned int SpecImage::countObject()
{
  return count; 
};

void SpecImage::writeImage()
{
	cout << "SpecImage with id = "<<getID() ;
	cout << *this;
	cout << "TubeImage:" << endl;
	cout << "Point: " << tube.getPoint() << "Height = " << tube.getHeight()<< "Width = " << tube.getWidth()<< endl;
}

int SpecImage::operator>(int e)
{

	if(this->body.getTrapeze().getH()>5) return 1;
		else return 0;
	
}
